package com.muyu.system.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.common.system.domain.LoginUser;
import com.muyu.system.domain.DanmoShoppingFlagship;
import com.muyu.system.req.DanmoShoppingFlagshipReq;
import com.muyu.system.req.DanmoShoppingProductsPriceReq;
import com.muyu.system.service.IDanmoShoppingFlagshipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 旗舰店Controller
 *
 * @author yangle
 * @date 2024-09-29
 */
@RestController
@RequestMapping("/flagship")
public class DanmoShoppingFlagshipController extends BaseController
{
    @Autowired
    private IDanmoShoppingFlagshipService danmoShoppingFlagshipService;

    /**
     * 查询旗舰店列表
     */
//    @RequiresPermissions  ("system:flagship:list")
    @PostMapping("/list")
    public Result list(@RequestBody DanmoShoppingFlagship danmoShoppingFlagship)
    {
        PageHelper.startPage(danmoShoppingFlagship.getPageNum(), danmoShoppingFlagship.getPageSize());
//        LoginUser loginUser = SecurityUtils.getLoginUser();
//        danmoShoppingFlagship.setUserId(loginUser.getUserid());
        List<DanmoShoppingFlagship> list = danmoShoppingFlagshipService.selectDanmoShoppingFlagshipList(danmoShoppingFlagship);
        PageInfo<DanmoShoppingFlagship> danmoShoppingFlagshipPageInfo = new PageInfo<>(list);
        return Result.success(danmoShoppingFlagshipPageInfo);
    }

    /**
     * 旗舰店知名度排序
     */
//    @RequiresPermissions("system:flagship:list")
    @PostMapping("/rankingOfPopularity")
    public Result rankingOfPopularity(@RequestBody DanmoShoppingProductsPriceReq danmoShoppingProductsPriceReq)
    {
        List<DanmoShoppingFlagship> list = danmoShoppingFlagshipService.selectDanmoShoppingFlagshipListRankingOfPopularity(danmoShoppingProductsPriceReq);
        return Result.success(list);
    }

    /**
     * 导出旗舰店列表
     */
//    @RequiresPermissions("system:flagship:export")
    @Log(title = "旗舰店", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoShoppingFlagship danmoShoppingFlagship)
    {
        List<DanmoShoppingFlagship> list = danmoShoppingFlagshipService.selectDanmoShoppingFlagshipList(danmoShoppingFlagship);
        ExcelUtil<DanmoShoppingFlagship> util = new ExcelUtil<DanmoShoppingFlagship>(DanmoShoppingFlagship.class);
        util.exportExcel(response, list, "旗舰店数据");
    }

    /**
     * 获取旗舰店详细信息
     */
//    @RequiresPermissions("system:flagship:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return success(danmoShoppingFlagshipService.selectDanmoShoppingFlagshipById(id));
    }

    /**
     * 新增旗舰店
     */
//    @RequiresPermissions("system:flagship:add")
    @Log(title = "旗舰店", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody DanmoShoppingFlagship danmoShoppingFlagship)
    {
        return toAjax(danmoShoppingFlagshipService.insertDanmoShoppingFlagship(danmoShoppingFlagship));
    }

    /**
     * 修改旗舰店
     */
//    @RequiresPermissions("system:flagship:edit")
    @Log(title = "旗舰店", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DanmoShoppingFlagship danmoShoppingFlagship)
    {
        return toAjax(danmoShoppingFlagshipService.updateDanmoShoppingFlagship(danmoShoppingFlagship));
    }

    /**
     * 删除旗舰店
     */
//    @RequiresPermissions("system:flagship:remove")
    @Log(title = "旗舰店", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        return toAjax(danmoShoppingFlagshipService.deleteDanmoShoppingFlagshipByIds(ids));
    }

    /**
     * 查詢旗舰店下的所有商品
     */
    @PostMapping("/listProducts")
    public Result listProducts(@RequestBody DanmoShoppingFlagshipReq danmoShoppingFlagshipReq)
    {
      List<DanmoShoppingFlagship> danmoShoppingProducts= danmoShoppingFlagshipService.listProducts(danmoShoppingFlagshipReq);
        return Result.success(danmoShoppingProducts);
    }

}
